package boot.spring.controller;

import boot.spring.model.entity.Intersection;
import boot.spring.service.IntersectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/intersections")
public class IntersectionController {

    @Autowired
    private IntersectionService intersectionService;

    @GetMapping("/within-bbox")
    public List<Intersection> getWithinBbox(
            @RequestParam double minX,
            @RequestParam double minY,
            @RequestParam double maxX,
            @RequestParam double maxY) {
        return intersectionService.getIntersectionsByBbox(minX, minY, maxX, maxY);
    }

    @GetMapping("/nearby")
    public List<Intersection> getNearby(
            @RequestParam double lng,
            @RequestParam double lat,
            @RequestParam double radius) {
        return intersectionService.getNearbyIntersections(lng, lat, radius);
    }

    @PostMapping("/within-polygon")
    public List<Intersection> getWithinPolygon(@RequestBody String polygonWkt) {
        return intersectionService.getIntersectionsByPolygon(polygonWkt);
    }
}